{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Sawnqa"

// By ArtemQa146

const
    Render_S = 31@
    Render_R = 30@
    Render_S2 = 29@

    Render_R2 = 27@

    Clip_X = 26@
    Clip_Y = 25@
    Clip_Z = 24@
    Clip_X2 = 22@
    Clip_Y2 = 21@
    Clip_Z2 = 20@
    addgunshell = 19@
    Weapon_ID = 26
end

0085: Render_S = 0@ // (int)
0085: Render_R = 1@ // (int)
0085: Render_S2 = 2@ // (int)
0085: Render_R2 = 3@ // (int)
        
        0A8C: write_memory 0x73A4E0 size 1 value 26 virtual_protect 0 //default 27
        
        0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 7@
        0E86: get_weaponinfo_flags 7@ store_to 7@
        if or
            7@ == 0x3833
            7@ == 0x3837
        then
            gosub @Visible_Weapon_Double
        else
            gosub @Visible_Weapon
        end

            repeat
            wait 0
            if and
                not actor.Driving($PLAYER_ACTOR)
                02D8:   actor $PLAYER_ACTOR current_weapon == Weapon_ID
            then
                0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 17@
                0E86: get_weaponinfo_flags 17@ store_to 17@
                if
                    803B:   not 7@ == 17@  // (int)
                then
                    gosub @Hide_Weapon_Double
                    if or
                        17@ == 0x3833
                        17@ == 0x3837
                    then
                        gosub @Visible_Weapon_Double
                    else
                        gosub @Visible_Weapon
                    end
                    0085: 7@ = 17@ // (int)
                end
                0A8D: 1@ = read_memory 0xB7CDD0 size 4 virtual_protect 0
                08C3: clear 1@ bit 12
                0A8C: write_memory 0xB7CDD0 size 4 value 1@ virtual_protect 0
                0A8C: write_memory 0x740CF0 size 4 value 0.0 virtual_protect 0 //0.30000001
                0A8C: write_memory 0x740CF8 size 4 value 0.0 virtual_protect 0 //0.44999999
                0E36: set_render_object_rotation Render_R 0 0 0
                0E36: set_render_object_rotation Render_R2 0 180.0 180.0

                    get_char_weapon_clip $PLAYER_ACTOR store_to 0@
                    if and
                        0@ > 0
                        not Actor.Animation($PLAYER_ACTOR) == "sawnoff_reload"
                        not Actor.Animation($PLAYER_ACTOR) == "colt45_crouchreload"
                    then
                        10@ = 0.0
                        9@ = 0
                        addgunshell = 0
                    end

                        if or
                            Actor.Animation($PLAYER_ACTOR) == "sawnoff_reload"
                            Actor.Animation($PLAYER_ACTOR) == "colt45_crouchreload"
                        then
                            if Actor.Animation($PLAYER_ACTOR) == "sawnoff_reload"
                            then 0613: 1@ = actor $PLAYER_ACTOR animation "sawnoff_reload" time
                            end
                            if Actor.Animation($PLAYER_ACTOR) == "colt45_crouchreload"
                            then 0613: 1@ = actor $PLAYER_ACTOR animation "colt45_crouchreload" time
                            end
                                if and
                                    9@ == 0
                                    1@ <= 0.9
                                    1@ >= 0.1
                                then
                                    10@ += 10.0
                                    if 10@ >= 90.0
                                    then 10@ = 90.0
                                    end
                                    0E36: set_render_object_rotation Render_R 0 10@ 0
                                    if
                                        10@ >= 90.0
                                    then
                                        gosub @Shell
                                    end
                                    if
                                        1@ >= 0.86
                                    then
                                        9@ = 1
                                        10@ = 180.0
                                        addgunshell = 0
                                    end
                                end
                                if or
                                    7@ == 0x3833
                                    7@ == 0x3837
                                then
                                    if and
                                        9@ == 1
                                        1@ <= 0.85
                                        1@ >= 0.1
                                    then
                                        10@ -= 10.0
                                        if 10@ <= 90.0
                                        then 10@ = 90.0
                                        end
                                        0E36: set_render_object_rotation Render_R2 0 10@ 180.0
                                        if
                                            10@ >= 90.0
                                        then
                                            gosub @Shell
                                        end
                                        if
                                            1@ >= 0.86
                                        then
                                            9@ = 2
                                            10@ = 0.0
                                        end
                                    end
                                end
                            end


            else
                break
            end
            until not player.Defined(0)
                0A8D: 1@ = read_memory 0xB7CDD0 size 4 virtual_protect 0
                08BD: set 1@ bit 12
                0A8C: write_memory 0xB7CDD0 size 4 value 1@ virtual_protect 0
                0A8C: write_memory 0x740CF0 size 4 value 0.30000001 virtual_protect 0 //0.30000001
                0A8C: write_memory 0x740CF8 size 4 value 0.44999999 virtual_protect 0 //0.44999999
                0A8C: write_memory 0x73A4E0 size 1 value 27 virtual_protect 0 //default 27
                if or
                    7@ == 0x3833
                    7@ == 0x3837
                then
                    gosub @Hide_Weapon_Double
                else
                    gosub @Hide_Weapon
                end
                
0A93: terminate_this_custom_script



:Hide_Weapon
0E31: set_render_object_visible Render_S 0
0E31: set_render_object_visible Render_R 0
return

:Visible_Weapon
0E31: set_render_object_visible Render_S 1
0E31: set_render_object_visible Render_R 1
return

:Hide_Weapon_Double
0E31: set_render_object_visible Render_S 0
0E31: set_render_object_visible Render_R 0
0E31: set_render_object_visible Render_S2 0
0E31: set_render_object_visible Render_R2 0
return

:Visible_Weapon_Double
0E31: set_render_object_visible Render_S 1
0E31: set_render_object_visible Render_R 1
0E31: set_render_object_visible Render_S2 1
0E31: set_render_object_visible Render_R2 1
return

:Shell
if and
    timera > 200
    addgunshell <= 1
then
    0A96: 6@ = ped $PLAYER_ACTOR struct
    0D4E: 5@ = struct 6@ offset 0x718 size 1 //active weap slot
    6@ += 0x5A0
    5@ *= 0x1C
    005A: 6@ += 5@ //CWeapon
    0172: 4@ = actor $PLAYER_ACTOR Z_angle
    2@ = 0.0
    3@ = 0.0
    if or
        4@ > 315.0
        4@ < 45.0
    then
        0208: 2@ = random_float_in_ranges 0.2 0.5
    else
        if and
            4@ > 135.0
            4@ < 225.0
        then
            0208: 2@ = random_float_in_ranges -0.5 -0.2
        else
            if and
                4@ > 225.0
                4@ < 315.0
            then
                0208: 3@ = random_float_in_ranges -0.5 -0.2
            else
                if and
                    4@ > 45.0
                    4@ < 135.0
                then
                    0208: 3@ = random_float_in_ranges 0.2 0.5
                end
            end
        end
    end
    if 9@ == 1
    then 0D0B: get_actor $PLAYER_ACTOR bone 34 matrix_pointer_to 4@ // IF and SET
    else 0D0B: get_actor $PLAYER_ACTOR bone 24 matrix_pointer_to 4@ // IF and SET
    end
    0D0A: store_coords_to 11@ 12@ 13@ from_matrix 4@ with_offsets 0.282 0.019 0.094
    0A96: 18@ = ped $PLAYER_ACTOR struct
    0AA6: call_method 0x73A3E0 struct 6@ num_params 4 pop 0 0.4 2@v 11@v 18@
    //0x73A3E0 void __thiscall CWeapon::AddGunshell(CWeapon *this, CEntity *entity, CVector *position, CVector2D *direction, float size)
    addgunshell += 1
    timera = 0
end
return
